package com.yhy.auth.handler;

import com.yhy.common.security.handler.AbstractAuthenticationFailureEventHandler;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.AuthenticationException;
import org.springframework.stereotype.Component;

/**
 * @author jax-li
 */
@Slf4j
@Component
@RequiredArgsConstructor
public class MyAuthenticationFailureEventHandler extends AbstractAuthenticationFailureEventHandler {

    public void handle(AuthenticationException exception, Authentication authentication) {
        log.info("用户：{} 登录失败：{}", authentication.getPrincipal(), exception.getLocalizedMessage());
        String userName = (String) authentication.getPrincipal();
        // 登录失败可以用通过用户名做key在中间件存储ttl判断是否需要锁定用户
    }

}